package com.wf.demo.sys.service;

import com.wf.demo.info.util.Page4Navigator;
import com.wf.demo.sys.dao.UserLoginTimeDAO;
import com.wf.demo.sys.pojo.SysLogEntity;
import com.wf.demo.sys.pojo.User;
import com.wf.demo.sys.pojo.UserTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: wf
 * @Date: 2020/6/20 17:11
 * @Description:
 */
@Service
public class UserLoginTimeService {
    @Autowired
    UserLoginTimeDAO userLoginTimeDAO;

    public List<UserTime> list(){
        Sort sort = new Sort(Sort.Direction.ASC,"id");
        return userLoginTimeDAO.findAll(sort);
    }
    public Page4Navigator<UserTime> list(int start, int size, int navigatePages){

        Sort sort = new Sort(Sort.Direction.DESC, "id");//id倒序排序，最新的记录在最前面
        Pageable pageable = new PageRequest(start, size, sort);
        Page pageFromJPA = userLoginTimeDAO.findBy(pageable);
        return new Page4Navigator<>(pageFromJPA,navigatePages);
    }
    public void delete(long id){
        userLoginTimeDAO.delete(id);
    }
    public void add(UserTime bean) {
        userLoginTimeDAO.save(bean);
    }
}
